@extends('home.parent')
@section('title','关键词表')
@section('head_js')
@endsection
@section('head_css')
<link rel="stylesheet" href="{{ asset('/css/toggleButtonsMain.css') }}">
@endsection
@section('content')
<style>
.content-personal{
	padding:10px 15px;
}
.content-personal div.col-md-6{
	border-top:1px solid #f2f2f2;
	padding-left:0;
	margin-bottom:10px;
}
.thall{
	background:#fff;
	color:#777;
}
.thall div.thall-header{
	padding:5px 10px;
	border-bottom:1px solid #f2f2f2;
	line-height:1.5;
	font-size:14px;
}
.thall div.thall-header a{
	float:right;
}
.thall div.thall-header font{
	color:red;
	margin-left:10px;
}
.thall div.thall-header font small{
	margin-left:50px;
}
.thall div.thall-table{
	padding:10px;
	max-height:760px;
	overflow-y:auto;
}
table{width:100%;}
table tr th,table tr td{
	padding:0 10px;
	border:1px solid #f8f8f8;
	white-space:nowrap;
}
table tr th{padding:10px;}
table thead tr{
	background:#f0f0f0;
}
table tbody tr:hover{
	background:#f3f3f3;
}
</style>
<div class="content-wrapper">
	<section class="content-header">
		<h1 id="user">	<input type="hidden" name="userid" id="userid" value="{{$data['id']}}">
			{{$data['user_name']}}的关键词列表
			<small></small>
		</h1>
	</section>
	<section class="content-personal">
		<div class="col-md-6">
			<div class="thall">
				<div class="thall-header">
					内容关键词<font>示例：多少钱、怎么买、合作<small></small>匹配相关的评论</font>
					<a href="javascript:;" class="btn btn-info btn-xs" title="添加关键词" onclick="addKey(0,0,'')"><i class="fa fa-plus"> 添加关键词</i></a>
					<div style="clear:both;"></div>
				</div>
				<div class="thall-table commentKey">
					<table>
						<thead>
							<tr>
								<th>名称</th>
								<th>时间</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody><tr><td colspan="10" style="padding:10px;">无数据</td><tr></tbody>
					</table>
				</div>
			</div>
		</div>
		<div class="col-md-6">
			<div class="thall">
				<div class="thall-header">
					标题关键词<font>最多同时开启15个，示例：美食、家具、瓷砖、钢<small></small>匹配相关的视频</font>
					<a href="javascript:;" class="btn btn-info btn-xs" title="添加关键词" onclick="addKey(1,0,'')"><i class="fa fa-plus"> 添加关键词</i></a>
					<div style="clear:both;">
					</div>
				</div>
				<div class="thall-table titleKey">
					<table>
						<thead>
							<tr>
								<th>名称</th>
								<th>时间</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody><tr><td colspan="10" style="padding:10px;">无数据</td><tr></tbody>
					</table>
				</div>
			</div>
		</div>
		<div style="clear:both;"></div>
	</section>
</div>
<div id="editKeyword" style="display:none;color:#777;padding:10px 20px 0 20px;">
	<label>关键词</label>
	<input type="text" class="form-control" name="name" id="name" placeholder="请输入关键词名称" maxlength="10">
	<input type="hidden" name="type">
	<input type="hidden" name="kid">

</div>
@endsection
@section('foot_js')
<script src="{{ asset('/js/tools.js') }}"></script>
<script>
	var userid=$('#user input[name="userid"]').val();
	$(document).ready(function() {

		ajaxCommentKey(userid,0);
		ajaxCommentKey(userid,1);
	});
//拉取关键词列表
function ajaxCommentKey(id,type){
	//
	var url = "{{URL('key/list')}}";
	var data = {id:id,type: type};
	var result = puppet.myajax('post', url, data, false);
	if (result.code == 0) {
		if(type){
			$('.titleKey tbody').html(result.html);
		}else{
			$('.commentKey tbody').html(result.html);
		}
	}
}
//修改关键词状态
function upStatus(kid,status,type){
	var userid=$('#user input[name="userid"]').val();
	var url = "{{URL('key/upStatus')}}";
	var data = {userid:userid,kid: kid,status: status,type: type};
	var re = puppet.myajax('post', url, data, false);
	if (re.code == 0) {
		layer.msg(re.msg, {icon:6});
		if(type){
			ajaxCommentKey(userid,1);//标题关键词
		}else{
			ajaxCommentKey(userid,0);//内容关键词
		}
	}else{
		event.preventDefault();
		layer.msg(re.msg, {icon:5});
	}
}
function del(kid,status,type,conText){
	layer.confirm(conText, {
		skin: "layui-layer-molv",
		btn: ['确认删除', '再考虑一下'] //按钮
	}, function () {
		upStatus(kid,status,type)
	}, function () {
		
	});
}
//添加关键词
function addKey(type,kid,name){
	var title='';
	if(type && kid){
		title='修改标题关键词';
	}else if(type && !kid){
		title='添加标题关键词';
	}else if(!type && kid){
		title='修改内容关键词';
	}else if(!type && !kid){
		title='添加内容关键词';
	}
	$('#editKeyword input[name="name"]').val(name);
	$('#editKeyword input[name="kid"]').val(kid);
	$('#editKeyword input[name="type"]').val(type);
	showlayerOne("editKeyword",title,saveKey);
}
//保存关键词
function saveKey(){
	var url = "{{URL('key/saveKey')}}";

	var userid=$('#user input[name="userid"]').val();
	var name=$('#editKeyword input[name="name"]').val();
	var kid=$('#editKeyword input[name="kid"]').val();
	var type=$('#editKeyword input[name="type"]').val();
	if(name==''){
		layer.msg("请输入关键词名称",{icon: 5});
		return false;
	}
	loading_show();
	$.ajax({
		type:'POST',
		url: "{{URL('key/saveKey')}}",
		data: {userid:userid,kid: kid,name: name,type: type},
		dataType:'json',
		success:function(r){
			loading_hidden();
			if(r.code==1){
				layer.msg(r.msg,{icon: 5});
			}else{
				layer.closeAll();
				layer.msg(r.msg,{icon: 6});
				if(type==1){
					ajaxCommentKey(userid,1);//标题关键词
				}else{
					ajaxCommentKey(userid,0);//内容关键词
				}
				layer.msg(re.msg, {icon:6,time:1000});
			}
		},
		error:function(){
			loading_hidden();
			layer.msg("网络错误",{icon: 5});
		}
	});
}
</script>
@endsection